﻿@namespace Sky.App.AIUI.Pages
@page "/Chat"
@using Microsoft.AspNetCore.Components.Web.Virtualization

<div class="page-content">
    <GridRow Gutter="(16, 16)">
        <GridCol Span="24">
            <Spin Size="@(SpinSize.Large)" Tip="思考ing......" Spinning="@(_isLoading)">
                <Card Style="height: 700px;">
                    <TitleTemplate>
                        <i class="fa fa-windows"></i> @("DeepSeek-Chat")
                    </TitleTemplate>
                    <Extra>

                    </Extra>
                    <Body>
                        <div id="scrollDiv" style="height: 530px; overflow-y: auto; overflow-x: hidden;">
                            @if (MessageList.Count > 0)
                            {
                                <GridRow Gutter="(8, 8)">
                                    <Virtualize Items="@(MessageList.OrderByDescending(o => o.CreateTime).ToList())" Context="item">
                                        <GridCol Span="24">
                                            <Card Size="@(CardSize.Small)">
                                                <TitleTemplate>
                                                    <Text Strong><Icon Type="bulb" /> @(item.Questions)</Text>
                                             </TitleTemplate>
                                             <Extra>
                                                 <Space>
                                                     <SpaceItem>
                                                         <a style="color: gray;" @onclick="@(async () => await OnCopyAsync(item))"><Icon Type="copy" /></a>
                                                     </SpaceItem>
                                                     <SpaceItem>
                                                         <a style="color: gray;" @onclick="@(async () => await OnClearAsync(item.ID))"><Icon Type="rest" /></a>
                                                     </SpaceItem>
                                                 </Space>
                                             </Extra>
                                             <Body>
                                                 @((MarkupString)item.HtmlAnswers)
                                             </Body>
                                         </Card>
                                     </GridCol>
                                 </Virtualize>
                             </GridRow>
                            }
                            else
                            {
                                <Alert Type="@(AlertType.Info)"
                                       Message="我叫DeepSeek，什么都知道，问吧！！！"
                                       ShowIcon="@(true)" />
                            }
                        </div>
                        <div style="height: 10px;"></div>
                        <AntDesign.Input @bind-Value="@(_messageInput)" DebounceMilliseconds="@(-1)" Placeholder="输入消息回车发送" OnPressEnter="@(async () => await OnSendAsync())">
                            <Suffix>
                                <Button Icon="send" Type="@(ButtonType.Link)" OnClick="@(async () => await OnSendAsync())" AutoLoading="@(true)"></Button>
                            </Suffix>
                        </AntDesign.Input>
                    </Body>
                </Card>
            </Spin>
        </GridCol>
    </GridRow>
</div>
